How to solve algebraic equation